package com.example.learnandroid;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    //旧版本对话框
    public void onOldButtonClicked(View view) {
        AlertDialog dialog;
        dialog = new AlertDialog.Builder(this).setTitle("旧版对话框")
                .setMessage("这是旧版的对话框,使用简单\n但是没有自动支持屏幕翻转!")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        Toast.makeText(getApplicationContext(), "你确定了!", Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        Toast.makeText(getApplicationContext(), "你取消了", Toast.LENGTH_SHORT).show();

                    }
                })
                .create();
        dialog.show();
    }

    //新版本对话框
    public void SimpleDialogFragmet(View view){
        SimpleDialogFragmet dialog = new SimpleDialogFragmet();
        dialog.show(getSupportFragmentManager(),"simple");
    }

    //选择对话框
    public void onChoiceButtonclicked(View view){
        ChoiceDialogFragment dialog = new ChoiceDialogFragment();
        dialog.setListener(new ChoiceDialogFragment.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(),"你选择了：" + gender, Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }

    //单选对话框
    public void onCreateDialog(View view){
        SingleChoiceCreateDialog dialog = new SingleChoiceCreateDialog();
        dialog.setListener(new SingleChoiceCreateDialog.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(),"你选择了：" + gender, Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }

    //多选对话框
    public void onMutipleCreateDialog(View view){
        MutipleChoiceCreateDialog dialog = new MutipleChoiceCreateDialog();
        dialog.setListener(new MutipleChoiceCreateDialog.NotifyDialogListener() {
            @Override
            public void onDialogPositiveClicked(String gender) {
                Toast.makeText(getApplicationContext(),"你选择了：" + gender, Toast.LENGTH_SHORT).show();
            }
        });
        dialog.show(getSupportFragmentManager(),"choice");
    }

    //自定义对话框
    public void onCustomlayout(View view){
        Customlayout dialog = new Customlayout();
        dialog.show(getSupportFragmentManager(), "choice");
    }
}

